#include <iostream>
#include <bits/stdc++.h>

using namespace std;

class Solution {
public:
    void rotate(vector<vector<int>> &matrix) {
        int n = matrix.size();
        //最外层
        int t = n;
        for (int i = 0; i <= n / 2; i++) {
            for (int j = i; j < n - i - 1; j++) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[n - 1 - j][i];
                matrix[n - 1 - j][i] = matrix[n - 1 - i][n - 1 - j];
                matrix[n - 1 - i][n - 1 - j] = matrix[j][n - 1 - i];
                matrix[j][n - 1 - i] = temp;
            }
        }

        for (const auto &rows: matrix) {
            for (const auto &val: rows) {
                cout << val << " ";
            }
            cout << "\n";
        }
    }
};


int main() {
    Solution solution;
    vector<vector<int>> matrix = {{5,  1,  9,  11},
                                  {2,  4,  8,  10},
                                  {13, 3,  6,  7},
                                  {15, 14, 12, 16}};
    solution.rotate(matrix);

    return 0;
}